﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class IntervalRetryPolicy : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IIntervalRetryPolicy
    {
        #region Public Members

        #region IntervalRetryPolicyId

        private System.Nullable<int> _IntervalRetryPolicyId;
        partial void OnBeforeIntervalRetryPolicyIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterIntervalRetryPolicyIdPropertyChanged();
        public System.Nullable<int> IntervalRetryPolicyId
        { 
            get
            {
                return _IntervalRetryPolicyId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IntervalRetryPolicyId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _IntervalRetryPolicyId);
                    OnBeforeIntervalRetryPolicyIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IntervalRetryPolicyId", eventData.Value, true, true);
                        OnAfterIntervalRetryPolicyIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxRetryCount

        private System.Nullable<int> _MaxRetryCount;
        partial void OnBeforeMaxRetryCountPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterMaxRetryCountPropertyChanged();
        public System.Nullable<int> MaxRetryCount
        { 
            get
            {
                return _MaxRetryCount;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxRetryCount = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _MaxRetryCount);
                    OnBeforeMaxRetryCountPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxRetryCount", eventData.Value, true, true);
                        OnAfterMaxRetryCountPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region RetryInterval

        private System.TimeSpan _RetryInterval;
        partial void OnBeforeRetryIntervalPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.TimeSpan> eventData);
        partial void OnAfterRetryIntervalPropertyChanged();
        public System.TimeSpan RetryInterval
        { 
            get
            {
                return _RetryInterval;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _RetryInterval = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.TimeSpan> eventData = new Sidvall.Business.PropertyChangeEventData<System.TimeSpan>(value, _RetryInterval);
                    OnBeforeRetryIntervalPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("RetryInterval", eventData.Value, true, true);
                        OnAfterRetryIntervalPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public IntervalRetryPolicy Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.Copy(this);
        }
        public IntervalRetryPolicy Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IIntervalRetryPolicy item)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IIntervalRetryPolicy item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.Initialize(this, settings);
        }

        #endregion

        #region IIntervalRetryPolicy Members

        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IIntervalRetryPolicy.IntervalRetryPolicyId
        {
            get
            {
                return this._IntervalRetryPolicyId;
            }
            set
            {
                this._IntervalRetryPolicyId = value;
            }
        }
        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IIntervalRetryPolicy.MaxRetryCount
        {
            get
            {
                return this._MaxRetryCount;
            }
            set
            {
                this._MaxRetryCount = value;
            }
        }
        System.TimeSpan global::Sidvall.WorkItemManager.Data.IIntervalRetryPolicy.RetryInterval
        {
            get
            {
                return this._RetryInterval;
            }
            set
            {
                this._RetryInterval = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public IntervalRetryPolicy()
        {
        }
        public IntervalRetryPolicy(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public IntervalRetryPolicy(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.IntervalRetryPolicyManager.Initialize(this);
        }

        #endregion
    }
}